// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var base = require("base");
	var databind = require("databind");
	var enterpriseId;
	var bulkstockInfoId;
	var goodsName;

	var init = function() {
		bulkstockInfoId = base.getUrlParam("bulkstockInfoId");
		goodsName = base.getUrlParam("goodsName");
		initEvent();
	};
	var initEvent = function() {
		inquireRankingDatas(enterpriseId, bulkstockInfoId);
	};

	var inquireRankingDatas = function(enterpriseId, bulkstockInfoId) {
		base.fnAjax({
			action: "inquireRankingDatas.json",
			async: true,
			nocode: true,
			oData: {
				type: 3,
				bulkstockInfoId: bulkstockInfoId,
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					data.x = [];
					data.y = [];
					$.each(data.datas, function() {
						var _this = this;
						data.x.push(_this.name);
						data.y.push(_this.value);
					});
//					showChart1(data);
					var chart = echarts.init(document.getElementById("chart"));
					var option = {
						title: {
							text: '客户放款排行',
							subtext: decodeURI(goodsName),
							x: 'center',
							left: 'center',
							textStyle: {
								color: "#566bfe",
								fontWeight: 'normal',
							},
							subtextStyle:{
								color: "#566bfe",
								fontSize:'14',
							}
						},
						color: ['#e43b3b'],
						tooltip: {
							trigger: 'axis',
							axisPointer: { // 坐标轴指示器，坐标轴触发有效
								type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
							}
						},
						grid: {
							left: '3%',
							right: '4%',
							bottom: '3%',
							containLabel: true
						},
						xAxis: [{
							type: 'category',
							data: data.x,
							axisTick: {
								alignWithLabel: true
							}
						}],
						yAxis: [{
							type: 'value'
						}],
						textStyle: {
							color: "#fff"
						},
						series: [{
							name: '直接访问',
							type: 'bar',
							barWidth: '60%',
							data: data.y
						}]
					};
					chart.setOption(option, true);
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};

	return {
		init: init
	};
});